home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 101-125 / 118 / empire / src / source.zoo / cmd_general4.d < prev    next >
Text File  |  1987-12-02  |  12KB  |  436 lines

  1. #include:util.g
  2. #empire.g
  3. #empfunc.g
  4.  
  5. proc cmd_price()bool:
  6.     Sector_t s;
  7.     Ship_t sh;
  8.     Offer_t offer;
  9.     uint offerNumber, shipNumber, cost, price, oldPrice;
  10.     int r, c;
  11.     ItemType_t what;
  12.     bool isShip, gotOffer;
  13.  
  14.     gotOffer := false;
  15.     if reqSectorOrShip(&r, &c, &shipNumber, &isShip,
  16.         "Ship to sell or exchange to sell at? ") then
  17.     if isShip then
  18.         readShip(shipNumber, sh);
  19.         if sh.sh_owner ~= ThisCountryNumber then
  20.         err("you don't own that ship");
  21.         false
  22.         else
  23.         offerNumber := 0;
  24.         while
  25.             if offerNumber = World.w_offerNext then
  26.             false
  27.             else
  28.             readOffer(offerNumber, offer);
  29.             offer.of_state ~= of_ship or
  30.                 offer.of_.of_shipNumber ~= shipNumber
  31.             fi
  32.         do
  33.             offerNumber := offerNumber + 1;
  34.         od;
  35.         if offerNumber ~= World.w_offerNext then
  36.             if offer.of_who ~= ThisCountryNumber then
  37.             sh.sh_price := 0;
  38.             fi;
  39.             gotOffer := true;
  40.         fi;
  41.         cost := World.w_shipCost[sh.sh_type];
  42.         write(Chout; getShipName(sh.sh_type), " \#", shipNumber);
  43.         if sh.sh_price = 0 then
  44.             writeln(Chout; " is currently not for sale");
  45.         else
  46.             writeln(Chout; " is currently offered at $", sh.sh_price,
  47.                 " per ton (total $", sh.sh_price * cost, ')');
  48.         fi;
  49.         skipBlanks();
  50.         if reqPosRange(&price, 127, "New price per ton? ") then
  51.             if price = 0 then
  52.             if sh.sh_price ~= 0 then
  53.                 writeln(Chout; "Lot \#",offerNumber, " withdrawn");
  54.                 sh.sh_price := 0;
  55.                 writeShip(shipNumber, sh);
  56.                 offer.of_state := of_none;
  57.                 writeOffer(offerNumber, offer);
  58.             else
  59.                 writeln(Chout; "OK, ship not offered for sale");
  60.             fi;
  61.             else
  62.             writeln(Chout; "Total value is $", price * cost);
  63.             sh.sh_price := price;
  64.             writeShip(shipNumber, sh);
  65.             if not gotOffer then
  66.                 offerNumber := World.w_offerNext;
  67.                 World.w_offerNext := World.w_offerNext + 1;
  68.             fi;
  69.             writeln(Chout; getShipName(sh.sh_type), " \#",
  70.                 shipNumber, " is now lot \#", offerNumber);
  71.             offer.of_state := of_ship;
  72.             offer.of_who := ThisCountryNumber;
  73.             offer.of_.of_shipNumber := shipNumber;
  74.             writeOffer(offerNumber, offer);
  75.             fi;
  76.         fi;
  77.         true
  78.         fi
  79.     elif doSkipBlanks() and reqCmsgpob(&what, "Set price on what? ") then
  80.         readSector(r, c, s);
  81.         if what = it_civilians or what = it_military then
  82.         err("can't sell people");
  83.         false
  84.         elif s.s_owner ~= ThisCountryNumber then
  85.         err("you don't own that sector");
  86.         false
  87.         elif s.s_type ~= s_exchange then
  88.         err("that sector is not an exchange");
  89.         false
  90.         elif s.s_efficiency < 60 then
  91.         err("exchange not efficient enough for trading");
  92.         false
  93.         else
  94.         offerNumber := s.s_threshold[it_civilians] << 8 |
  95.                    s.s_threshold[it_military];
  96.         cost := getItemCost(what);
  97.         oldPrice := s.s_threshold[what] * cost;
  98.         if offerNumber ~= 0 then
  99.             offerNumber := offerNumber - 1;
  100.             readOffer(offerNumber, offer);
  101.             if offer.of_who ~= ThisCountryNumber then
  102.             oldPrice := 0;
  103.             fi;
  104.             gotOffer := true;
  105.         fi;
  106.         write(Chout; getItemName(what));
  107.         if oldPrice = 0 then
  108.             write(Chout; " currently not for sale");
  109.         else
  110.             write(Chout; " currently offered at $",
  111.               oldPrice / 10, '.', oldPrice % 10, '0');
  112.         fi;
  113.         writeln(Chout; " at ", r, ',', c);
  114.         skipBlanks();
  115.         if reqPosRange1(&price, cost * 127, "New price? ") then
  116.             if price / cost = 0 and price ~= 0 then
  117.             writeln(Chout; "Price too low, must be at least $",
  118.                 cost / 10, '.', cost % 10, '0');
  119.             else
  120.             price := price / cost;
  121.             if price = 0 then
  122.                 if oldPrice = 0 then
  123.                 writeln(Chout; "OK, ", getItemName(what),
  124.                     " not offered");
  125.                 else
  126.                 s.s_threshold[what] := 0;
  127.                 if s.s_threshold[it_shells] = 0 and
  128.                     s.s_threshold[it_guns] = 0 and
  129.                     s.s_threshold[it_planes] = 0 and
  130.                     s.s_threshold[it_ore] = 0 and
  131.                     s.s_threshold[it_bars] = 0 then
  132.                     offer.of_state := of_none;
  133.                     writeOffer(offerNumber, offer);
  134.                     writeln(Chout; "Lot \#", offerNumber,
  135.                         " withdrawn");
  136.                     s.s_threshold[it_civilians] := 0;
  137.                     s.s_threshold[it_military] := 0;
  138.                 fi;
  139.                 writeSector(r, c, s);
  140.                 fi;
  141.             else
  142.                 writeln(Chout; "Price set to $", price * cost / 10,
  143.                     '.', price * cost % 10, '0');
  144.                 if not gotOffer then
  145.                 offerNumber := World.w_offerNext;
  146.                 World.w_offerNext := World.w_offerNext + 1;
  147.                 writeln(Chout; "This item is lot \#",
  148.                     offerNumber);
  149.                 else
  150.                 writeln(Chout; "Lot \#", offerNumber,
  151.                     " updated");
  152.                 fi;
  153.                 offer.of_state := of_sector;
  154.                 offer.of_who := ThisCountryNumber;
  155.                 offer.of_.of_sect.of_row := transRow(r);
  156.                 offer.of_.of_sect.of_col := transCol(c);
  157.                 writeOffer(offerNumber, offer);
  158.                 s.s_threshold[it_civilians] :=
  159.                     World.w_offerNext >> 8;
  160.                 s.s_threshold[it_military] := World.w_offerNext;
  161.                 s.s_threshold[what] := price;
  162.                 writeSector(r, c, s);
  163.             fi;
  164.             fi;
  165.         else
  166.             if oldPrice = 0 then
  167.             writeln(Chout; "OK, ", getItemName(what),
  168.                 " not offered");
  169.             else
  170.             writeln(Chout; "OK, price not changed");
  171.             fi;
  172.         fi;
  173.         true
  174.         fi
  175.     else
  176.         false
  177.     fi
  178.     else
  179.     false
  180.     fi
  181. corp;
  182.  
  183. /*
  184.  * printOffer - print out an offer. Return 'false' if it is gone.
  185.  */
  186.  
  187. proc printOffer(uint offerNumber; Offer_t offer)bool:
  188.     Sector_t s;
  189.     Ship_t ship;
  190.     uint cost;
  191.     int r, c;
  192.     ItemType_t it;
  193.     bool needMess;
  194.  
  195.     needMess := false;
  196.     if offer.of_state = of_ship then
  197.     readShip(offer.of_.of_shipNumber, ship);
  198.     if ship.sh_owner ~= offer.of_who then
  199.         offer.of_state := of_none;
  200.         writeOffer(offerNumber, offer);
  201.         ship.sh_price := 0;
  202.         writeShip(offer.of_.of_shipNumber, ship);
  203.         needMess := true;
  204.     else
  205.         writeln(Chout; "Lot \#", offerNumber, ':');
  206.         writeln(Chout; getShipName(ship.sh_type), " \#",
  207.             offer.of_.of_shipNumber, " at ",
  208.             unTransRow(ThisCountryNumber, ship.sh_row), ',',
  209.             unTransCol(ThisCountryNumber, ship.sh_col),
  210.             ": ", ship.sh_efficiency, "%, crew: ",
  211.             ship.sh_crew, ", guns: ", ship.sh_guns,
  212.             ", shells: ", ship.sh_shells, " @ $", ship.sh_price,
  213.             " (total $",
  214.             ship.sh_price * World.w_shipCost[ship.sh_type], ')');
  215.     fi;
  216.     elif offer.of_state = of_sector then
  217.     r := unTransRow(ThisCountryNumber, offer.of_.of_sect.of_row);
  218.     c := unTransCol(ThisCountryNumber, offer.of_.of_sect.of_col);
  219.     readSector(r, c, s);
  220.     if s.s_owner ~= offer.of_who or s.s_type ~= s_exchange or
  221.         s.s_efficiency < 60 then
  222.         offer.of_state := of_none;
  223.         writeOffer(offerNumber, offer);
  224.         for it from it_first upto it_last do
  225.         s.s_threshold[it] := 0;
  226.         od;
  227.         writeSector(r, c, s);
  228.         needMess := true;
  229.     else
  230.         writeln(Chout; "Lot \#", offerNumber, ':');
  231.         for it from it_shells upto it_bars do
  232.         cost := getItemCost(it) * s.s_threshold[it];
  233.         if cost ~= 0 then
  234.             write(Chout; readQuan(s, it), ' ', getItemName(it), " @ $",
  235.               cost / 10, '.', cost % 10, "0  ");
  236.         fi;
  237.         od;
  238.         writeln(Chout;);
  239.     fi;
  240.     fi;
  241.     if needMess then
  242.     if offer.of_who = ThisCountryNumber then
  243.         writeln(Chout; "Your lot \#", offerNumber, " cancelled");
  244.     else
  245.         telegramStart(DEITY, offer.of_who);
  246.         writeln(TelegramChannel; "Your lot \#", offerNumber, " cancelled");
  247.         telegramEnd();
  248.     fi;
  249.     fi;
  250.     offer.of_state ~= of_none
  251. corp;
  252.  
  253. proc cmd_report()bool:
  254.     Offer_t offer;
  255.     uint choice, offerNumber;
  256.     bool doNaval, doLand;
  257.  
  258.     if InputPtr* >= '0' and InputPtr* <= '9' and World.w_offerNext ~= 0 then
  259.     if getPosRange(&offerNumber, World.w_offerNext - 1) then
  260.         readOffer(offerNumber, offer);
  261.         pretend(printOffer(offerNumber, offer), void);
  262.         true
  263.     else
  264.         false
  265.     fi
  266.     else
  267.     doNaval := true;
  268.     doLand := true;
  269.     if InputPtr* ~= '\e' then
  270.         doNaval := false;
  271.         doLand := false;
  272.         if getChoice(&choice, "naval\eland\e") then
  273.         if choice = 0 then
  274.             doNaval := true;
  275.         else
  276.             doLand := true;
  277.         fi;
  278.         fi;
  279.     fi;
  280.     if doLand or doNaval then
  281.         write(Chout; "        Empire Trade Report as of ");
  282.         writeDate(CurrentTime());
  283.         writeln(Chout;);
  284.         writeln(Chout;);
  285.         if World.w_offerNext ~= 0 then
  286.         for offerNumber from 0 upto World.w_offerNext - 1 do
  287.             readOffer(offerNumber, offer);
  288.             if (offer.of_state = of_ship and doNaval or
  289.                 offer.of_state = of_sector and doLand) and
  290.                 printOffer(offerNumber, offer) then
  291.             writeln(Chout;);
  292.             fi;
  293.         od;
  294.         fi;
  295.         true
  296.     else
  297.         false
  298.     fi
  299.     fi
  300. corp;
  301.  
  302. /*
  303.  * doBuy - try to buy a given item from an exchange sector. Return 'true' if
  304.  *    we should continue, 'false' if insufficient funds.
  305.  */
  306.  
  307. proc doBuy(Sector_t s1, s2; ItemType_t what; *ulong pFunds)bool:
  308.     uint cost, count, max;
  309.     [100] char buff;
  310.     channel output text promptChannel;
  311.  
  312.     cost := getItemCost(what) * s1.s_threshold[what];
  313.     if cost ~= 0 then
  314.     /* note assumption that bundle size in exchange is 1 for everything */
  315.     max := min(readQuan(s1, what), 127 - readQuan(s2, what));
  316.     open(promptChannel, &buff[0]);
  317.     write(promptChannel; "Buy how many ", getItemName(what), " at $",
  318.           cost / 10, '.', cost % 10, "0 (max ", max, ")? ");
  319.     close(promptChannel);
  320.     if reqPosRange(&count, max, &buff[0]) then
  321.         cost := cost * count / 10;
  322.         if pFunds* > cost then
  323.         writeQuan(s1, what, readQuan(s1, what) - count);
  324.         pFunds* := pFunds* - cost;
  325.         writeQuan(s2, what, readQuan(s2, what) + count);
  326.         true
  327.         else
  328.         err("insufficient funds");
  329.         false
  330.         fi
  331.     else
  332.         writeln(Chout; "OK, none bought");
  333.         true
  334.     fi
  335.     else
  336.     true
  337.     fi
  338. corp;
  339.  
  340. /*
  341.  * makeSale - a sale for the given amount has been made.
  342.  */
  343.  
  344. proc makeSale(uint seller, offerNumber; ulong amount)void:
  345.  
  346.     ThisCountry*.c_money := ThisCountry*.c_money - amount;
  347.     Country[seller].c_money := Country[seller].c_money + amount;
  348.     telegramStart(DEITY, seller);
  349.     writeln(TelegramChannel; "You made a sale (lot \#", offerNumber,
  350.         ") to ", &ThisCountry*.c_name[0]);
  351.     telegramEnd();
  352.     news(n_make_sale, seller, ThisCountryNumber);
  353.     writeln(Chout; "You are now $", amount, " poorer!");
  354. corp;
  355.  
  356. proc cmd_buy()bool:
  357.     Offer_t offer;
  358.     Ship_t ship;
  359.     Sector_t s1, s2;
  360.     long cost;
  361.     ulong funds;
  362.     uint which;
  363.     int r1, c1, r2, c2;
  364.  
  365.     if reqPosRange(&which, World.w_offerNext - 1, "Buy which lot? ") then
  366.     readOffer(which, offer);
  367.     if printOffer(which, offer) then
  368.         if offer.of_who = ThisCountryNumber then
  369.         err("can't sell to yourself");
  370.         false
  371.         elif offer.of_state = of_ship then
  372.         readShip(offer.of_.of_shipNumber, ship);
  373.         cost := ship.sh_price * World.w_shipCost[ship.sh_type];
  374.         if cost < ThisCountry*.c_money then
  375.             if ask("Buy the ship? ") then
  376.             ship.sh_price := 0;
  377.             ship.sh_owner := ThisCountryNumber;
  378.             writeShip(offer.of_.of_shipNumber, ship);
  379.             offer.of_state := of_none;
  380.             writeOffer(which, offer);
  381.             writeln(Chout; "You now own ",
  382.                 getShipName(ship.sh_type),
  383.                 " \#", offer.of_.of_shipNumber);
  384.             makeSale(offer.of_who, which, cost);
  385.             else
  386.             writeln("OK, you chickened out");
  387.             fi;
  388.         else
  389.             err("you don't have enough money");
  390.         fi;
  391.         true
  392.         else    /* offer.of_state = of_sector */
  393.         skipBlanks();
  394.         if reqSector(&r2, &c2, "Exchange to deliver to? ") then
  395.             readSector(r2, c2, s2);
  396.             if s2.s_owner ~= ThisCountryNumber then
  397.             err("you don't own that sector");
  398.             elif s2.s_type ~= s_exchange then
  399.             err("that sector is not an exchange");
  400.             elif s2.s_efficiency < 60 then
  401.             err("exchange not efficient enough yet");
  402.             else
  403.             funds := ThisCountry*.c_money;
  404.             r1 := unTransRow(ThisCountryNumber,
  405.                      offer.of_.of_sect.of_row);
  406.             c1 := unTransCol(ThisCountryNumber,
  407.                      offer.of_.of_sect.of_col);
  408.             readSector(r1, c1, s1);
  409.             if doBuy(s1, s2, it_shells, &funds) and
  410.                 doBuy(s1, s2, it_guns, &funds) and
  411.                 doBuy(s1, s2, it_planes, &funds) and
  412.                 doBuy(s1, s2, it_ore, &funds) and
  413.                 doBuy(s1, s2, it_bars, &funds) then
  414.                 if funds ~= ThisCountry*.c_money then
  415.                 writeSector(r1, c1, s1);
  416.                 writeSector(r2, c2, s2);
  417.                 /* the offer sticks around */
  418.                 makeSale(offer.of_who, which,
  419.                      ThisCountry*.c_money - funds);
  420.                 fi;
  421.             fi;
  422.             fi;
  423.             true
  424.         else
  425.             false
  426.         fi
  427.         fi
  428.     else
  429.         writeln(Chout; "Lot \#", which, " is not available");
  430.         false
  431.     fi
  432.     else
  433.     false
  434.     fi
  435. corp;
  436.